#!/bin/bash

# =============================================================================
# Fedora Workstation 42 自动化配置脚本
# 功能：系统更新、Flatpak 配置、GNOME 扩展安装、主题美化等
# 使用方法：chmod +x fedora-setup.sh && ./fedora-setup.sh
# 注意：请在全新安装的 Fedora 系统上运行
# 脚本存放位置：阿里网盘网页版 https://www.aliyundrive.com
# cd ~/下载 && git clone https://gitee.com/lcqh2635/init-fedora.git
# =============================================================================

# 设置颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# 打印彩色信息函数
print_info() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# 检查是否以 root 权限运行（部分操作需要）
check_root() {
    if [ "$EUID" -eq 0 ]; then
        print_error "请不要以 root 用户运行此脚本！"
        print_info "脚本会自动使用 sudo 执行需要管理员权限的操作。"
        exit 1
    fi
}

# 应用默认配置
apply_default_settings() {
    print_info "正在应用默认配置..."
    
    # gsettings list-schemas
    # gsettings list-recursively org.gnome.shell
    # gsettings list-recursively org.gnome.mutter
    # gsettings list-recursively org.gnome.desktop.interface
    # gsettings list-recursively org.gnome.desktop.wm.preferences
    # gsettings list-recursively org.gnome.Settings

    # gsettings 修改的是当前用户的 GNOME 配置，必须由 桌面用户（而非 root）执行。如果脚本通过 sudo 运行，命令会被忽略。
    # 设置窗口按钮位置 (右)
    gsettings set org.gnome.desktop.wm.preferences button-layout 'appmenu:minimize,maximize,close'
    # 设置新窗口居中显示
    gsettings set org.gnome.mutter center-new-windows true
    # 设置电量百分比
    gsettings set org.gnome.desktop.interface show-battery-percentage true
    # 显示星期几
    gsettings set org.gnome.desktop.interface clock-show-weekday true
    # 开启夜灯
    gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true
    # 设置夜灯温度（色温，范围 1000~10000，默认约 2700 色温严重偏黄，越小越黄）
    gsettings set org.gnome.settings-daemon.plugins.color night-light-temperature 4000
    # gsettings get org.gnome.settings-daemon.plugins.color night-light-temperature
    # gsettings reset org.gnome.settings-daemon.plugins.color night-light-temperature
    gsettings set org.gnome.settings-daemon.plugins.color night-light-schedule-from 18.0
    gsettings set org.gnome.settings-daemon.plugins.color night-light-schedule-to 8.0
    
    # 查看当前缩放比例
    # gsettings get org.gnome.desktop.interface scaling-factor
    # gsettings get org.gnome.mutter experimental-features
    # 设置整数缩放（1 = 100%, 2 = 200%）
    # gsettings set org.gnome.desktop.interface scaling-factor 2
    # 启用分数缩放（允许 125%、150% 等）
    # gsettings set org.gnome.mutter experimental-features "['scale-monitor-framebuffer']"
    # 设置分数缩放比例（例如 1.5 = 150%）
    # gsettings set org.gnome.desktop.interface text-scaling-factor 1.0  # 文字缩放（不推荐单独用）
    
    
    # gsettings list-recursively org.gnome.Settings
    # gsettings list-recursively org.gnome.settings-daemon.plugins

    # 系统外观主题和Gnome扩展插件优化
    # 自定义快捷键优化，Super-管理窗口、Alt-管理工作区
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-last "['<Alt>End']"
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-left "['<Alt>Left']"
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-right "['<Alt>Right']"
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<Alt>1']"
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-2 "['<Alt>2']"
    gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-3 "['<Alt>3']"
    # 当前工作区内的窗口切换
    gsettings set org.gnome.desktop.wm.keybindings switch-windows "['<Super>T']"
    # 窗口在工作区移动
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-last "['<Alt><Super>End']"
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-left "['<Alt><Super>Left']"
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-right "['<Alt><Super>Right']"
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-1 "['<Alt><Super>1']"
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-2 "['<Alt><Super>2']"
    gsettings set org.gnome.desktop.wm.keybindings move-to-workspace-3 "['<Alt><Super>3']"
    # 隐藏/显示当前工作区的所有窗口
    gsettings set org.gnome.desktop.wm.keybindings show-desktop "['<Alt><Super>h']"
    # 键盘 F 功能键
    # gsettings list-recursively org.gnome.settings-daemon.plugins.media-keys
    # 媒体声音控制
    gsettings set org.gnome.settings-daemon.plugins.media-keys mic-mute "['F2']"
    gsettings set org.gnome.settings-daemon.plugins.media-keys volume-down "['F3']"
    gsettings set org.gnome.settings-daemon.plugins.media-keys volume-up "['F4']"
    # 弹出 U 盘
    gsettings set org.gnome.settings-daemon.plugins.media-keys eject "['F5']"
    # 播放器控制
    gsettings set org.gnome.settings-daemon.plugins.media-keys next "['F8']"
    gsettings set org.gnome.settings-daemon.plugins.media-keys play "['F9']"
    gsettings set org.gnome.settings-daemon.plugins.media-keys previous "['F10']"
    
    
    mkdir -p ~/.local/share/backgrounds
    cp -v ~/下载/init-fedora/wallpaper.jpg ~/.local/share/backgrounds/
    gsettings set org.gnome.desktop.background picture-uri "file://$HOME/.local/share/backgrounds/wallpaper.jpg"
    
    # 添加文件模板
    cp -v ~/下载/init-fedora/模板/* ~/模板/
    
    print_success "默认配置应用完成！"
}

# 更新系统
update_system() {
    print_info "正在更新系统软件包..."
    sudo dnf upgrade -y
    if [ $? -eq 0 ]; then
        print_success "系统更新完成！"
    else
        print_error "系统更新失败！"
    fi
}

# 配置 GNOME 扩展
configure_gnome_extensions() {
    print_info "正在启用并配置 GNOME 扩展..."
    # 启用系统 GNOME 扩展
    gnome-extensions enable appindicatorsupport@rgcjonas.gmail.com
    gnome-extensions enable auto-move-windows@gnome-shell-extensions.gcampax.github.com
    gnome-extensions enable blur-my-shell@aunetx
    gnome-extensions enable caffeine@patapon.info
    gnome-extensions enable dash-to-dock@micxgx.gmail.com
    gnome-extensions enable just-perfection-desktop@just-perfection
    gnome-extensions enable no-overview@fthx
    gnome-extensions enable drive-menu@gnome-shell-extensions.gcampax.github.com
    gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com
    gnome-extensions enable workspace-indicator@gnome-shell-extensions.gcampax.github.com

    # 列出所有已安装的 Schema
    # gsettings list-schemas

    print_info "正在配置Background Logo..."
    # 设置 Background Logo 扩展插件
    # gsettings list-recursively org.fedorahosted.background-logo-extension
    # gsettings set org.fedorahosted.background-logo-extension logo-size 9.0
    gsettings set org.fedorahosted.background-logo-extension logo-always-visible true
    # 恢复默认设置
    # gsettings reset-recursively org.fedorahosted.background-logo-extension

    print_info "正在配置Blur My Shell..."
    # 配置 Blur My Shell (透明模糊效果)
    # gsettings list-recursively org.gnome.shell.extensions.blur-my-shell.panel
    # gsettings list-recursively org.gnome.shell.extensions.blur-my-shell.applications
    # 恢复默认设置 gsettings reset-recursively org.gnome.shell.extensions.blur-my-shell
    # 设置自定义模糊效果
    # gsettings get org.gnome.shell.extensions.blur-my-shell pipelines
    gsettings set org.gnome.shell.extensions.blur-my-shell pipelines "{'pipeline_default': {'name': <'Default'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_96853877854398'>, 'params': <@a{sv} {}>}>]>}, 'pipeline_panel': {'name': <'blur panel'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_75271904090067'>, 'params': <{'unscaled_radius': <100>, 'brightness': <1>}>}>, <{'type': <'color'>, 'id': <'effect_36769853581304'>, 'params': <{'color': <(0.4, 0.7, 0.9, 0.3)>}>}>]>}, 'pipeline_dock': {'name': <'blur dock'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_05617311186362'>, 'params': <{'unscaled_radius': <100>, 'brightness': <1>}>}>, <{'type': <'corner'>, 'id': <'effect_78081442948590'>, 'params': <{'radius': <20>}>}>]>}}"
    gsettings set org.gnome.shell.extensions.blur-my-shell.panel pipeline 'pipeline_panel'
    gsettings set org.gnome.shell.extensions.blur-my-shell.panel force-light-text true
    gsettings set org.gnome.shell.extensions.blur-my-shell.panel style-panel 1
    gsettings set org.gnome.shell.extensions.blur-my-shell.panel unblur-in-overview false
    gsettings set org.gnome.shell.extensions.blur-my-shell.hidetopbar compatibility true
    gsettings set org.gnome.shell.extensions.blur-my-shell.appfolder style-dialogs 2
    gsettings set org.gnome.shell.extensions.blur-my-shell.dash-to-dock pipeline 'pipeline_dock'
    gsettings set org.gnome.shell.extensions.blur-my-shell.dash-to-dock style-dash-to-dock 1
    # 启用应用程序窗口模糊
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications blur true
    # 启用自定义设置（必须为true才能生效）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications customize true
    # 颜色叠加（RGBA，此处为透明黑色，增强暗色模式对比度）
    # gsettings reset org.gnome.shell.extensions.blur-my-shell.applications color
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications color "(0.05, 0.05, 0.05, 0.1)"
    # 噪点强度（0.3=轻微颗粒感，模拟真实磨砂玻璃）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications noise-amount 0.3
    # 噪点明度（0.1=低对比噪点，自然不刺眼）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications noise-lightness 0.1
    # 模糊强度（50=中等模糊，过高会显脏）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications sigma 50
    # 亮度微调（1.0=原始亮度，建议保持）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications brightness 1.0
    # 基础透明度（220/255≈86%，平衡通透与朦胧感）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications opacity 220
    # 禁用动态透明度（避免窗口切换时效果闪烁）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications dynamic-opacity false
    # 禁用在Overview（超级键视图）中模糊（避免卡顿）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications blur-on-overview false
    # 不强制所有应用模糊（避免兼容性问题）
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications enable-all false
    # 应用毛玻璃效果的应用列表
    gsettings set org.gnome.shell.extensions.blur-my-shell.applications whitelist "['org.gnome.Settings', 'org.gnome.Software', 'org.gnome.TextEditor', 'org.gnome.Ptyxis', 'org.gnome.SystemMonitor', 'org.gnome.tweaks', 'org.gnome.Extensions', 'com.mattjakeman.ExtensionManager']"
    gsettings set org.gnome.shell.extensions.blur-my-shell.coverflow-alt-tab blur false

    # 递归列出某个 Schema 的键值（例如 org.gnome.shell.extensions.dash-to-dock）
    # gsettings list-recursively org.gnome.shell.extensions.dash-to-dock
    print_info "正在配置Dash to Dock..."
    # 配置 Dash to Dock (自定义Dock栏)
    gsettings set org.gnome.shell.extensions.dash-to-dock dock-position 'BOTTOM'
    gsettings set org.gnome.shell.extensions.dash-to-dock animation-time 0.5
    gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts false
    gsettings set org.gnome.shell.extensions.dash-to-dock hot-keys false
    gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'
    gsettings set org.gnome.shell.extensions.dash-to-dock scroll-action 'cycle-windows'
    gsettings set org.gnome.shell.extensions.dash-to-dock custom-theme-shrink true
    gsettings set org.gnome.shell.extensions.dash-to-dock running-indicator-style 'DASHES'
    gsettings set org.gnome.shell.extensions.dash-to-dock running-indicator-dominant-color true
    gsettings set org.gnome.shell.extensions.dash-to-dock custom-background-color true
    gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(153,193,241)'
    gsettings set org.gnome.shell.extensions.dash-to-dock transparency-mode 'FIXED'
    gsettings set org.gnome.shell.extensions.dash-to-dock background-opacity 0.3
    # 恢复默认设置
    # gsettings reset-recursively org.gnome.shell.extensions.dash-to-dock
    # 默认主题色/强调色，蓝色
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(153,193,241)'
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(26,95,180)'
    # 绿色
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(143,240,164)'
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(38,162,105)'
    # 紫色
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(220,138,221)'
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(97,53,131)'
    # 将 panel 一同切换为紫色
    # gsettings set org.gnome.shell.extensions.blur-my-shell pipelines "{'pipeline_default': {'name': <'Default'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_96853877854398'>, 'params': <@a{sv} {}>}>]>}, 'pipeline_panel': {'name': <'blur panel'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_75271904090067'>, 'params': <{'unscaled_radius': <100>, 'brightness': <1>}>}>, <{'type': <'color'>, 'id': <'effect_36769853581304'>, 'params': <{'color': <(0.9, 0.4, 0.8, 0.3)>}>}>]>}, 'pipeline_dock': {'name': <'blur dock'>, 'effects': <[<{'type': <'native_static_gaussian_blur'>, 'id': <'effect_05617311186362'>, 'params': <{'unscaled_radius': <100>, 'brightness': <1>}>}>, <{'type': <'corner'>, 'id': <'effect_78081442948590'>, 'params': <{'radius': <20>}>}>]>}}"
    # 白色
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(255,255,255)'
    # gsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(154,153,150)'

    print_info "正在配置Just Perfection..."
    # Just Perfection（微调 GNOME Shell 的细节，隐藏冗余元素、调整动画速度等）
    # gsettings list-recursively org.gnome.shell.extensions.just-perfection
    gsettings set org.gnome.shell.extensions.just-perfection accessibility-menu false
    gsettings set org.gnome.shell.extensions.just-perfection activities-button false
    gsettings set org.gnome.shell.extensions.just-perfection world-clock false
    gsettings set org.gnome.shell.extensions.just-perfection events-button false
    gsettings set org.gnome.shell.extensions.just-perfection weather false
    # 概览中工作区切换区缩略图，此处设置为隐藏
    # gsettings set org.gnome.shell.extensions.just-perfection workspace false
    gsettings set org.gnome.shell.extensions.just-perfection window-demands-attention-focus true
    gsettings set org.gnome.shell.extensions.just-perfection startup-status 0
    # gsettings reset-recursively org.gnome.shell.extensions.just-perfection
    
    # gsettings list-recursively org.gnome.shell.extensions.forge
    # 默认不启用窗口平铺模式
    # gsettings set org.gnome.shell.extensions.forge tiling-mode-enabled false
    # gnome-extensions enable forge@jmmaranan.com
    
    # 禁用动态工作区
    # gsettings set org.gnome.mutter dynamic-workspaces false
    # 设置工作区数量为3（奇数确保有中间位）
    # gsettings set org.gnome.desktop.wm.preferences num-workspaces 3
    # 预设工作区名称
    gsettings set org.gnome.desktop.wm.preferences workspace-names "['休闲区', '工作区']"
    
    # nautilus ~/.local/share/gnome-shell/extensions
    # 用户 GNOME 扩展 gnome-extensions list
    gnome-extensions enable add-to-desktop@tommimon.github.com
    gnome-extensions enable appmenu-is-back@fthx
    gnome-extensions enable Bluetooth-Battery-Meter@maniacx.github.com
    gnome-extensions enable clipboard-indicator@tudmotu.com
    gnome-extensions enable compiz-alike-magic-lamp-effect@hermes83.github.com
    gnome-extensions enable CoverflowAltTab@palatis.blogspot.com
    gnome-extensions enable ddterm@amezin.github.com
    gnome-extensions enable disable-unredirect@exeos
    gnome-extensions enable gtk4-ding@smedius.gitlab.com
    gnome-extensions enable hidetopbar@mathieu.bidon.ca
    gnome-extensions enable ibus-tweaker@tuberry.github.com
    gnome-extensions enable logomenu@aryan_k
    gnome-extensions enable nightthemeswitcher@romainvigier.fr
    gnome-extensions enable quick-settings-tweaks@qwreey
    gnome-extensions enable Rounded_Corners@lennart-k
    gnome-extensions enable rounded-window-corners@fxgn
    gnome-extensions enable search-light@icedman.github.com
    gnome-extensions enable show-desktop-button@amivaleo
    gnome-extensions enable status-area-horizontal-spacing@mathematical.coffee.gmail.com
    gnome-extensions enable top-bar-organizer@julian.gse.jsts.xyz
    
    # 解决用户 Gnome 扩展无法使用 gsettings 的问题
    for EXT_DIR in ~/.local/share/gnome-shell/extensions/*/; do
        EXT_ID=$(basename "$EXT_DIR")
        echo "处理扩展: $EXT_ID"
        if [ -d "$EXT_DIR/schemas" ]; then
            glib-compile-schemas "$EXT_DIR/schemas"
            mkdir -p ~/.local/share/glib-2.0/schemas/
            cp "$EXT_DIR/schemas"/*.xml ~/.local/share/glib-2.0/schemas/
        fi
    done
    glib-compile-schemas ~/.local/share/glib-2.0/schemas/
    
    print_info "正在配置Clipboard Indicator..."
    # Clipboard Indicator
    # gsettings list-recursively org.gnome.shell.extensions.clipboard-indicator
    gsettings set org.gnome.shell.extensions.clipboard-indicator history-size 10
    gsettings set org.gnome.shell.extensions.clipboard-indicator cache-images false
    # gsettings reset-recursively org.gnome.shell.extensions.clipboard-indicator

    print_info "正在配置Coverflow Alt-Tab..."
    # Coverflow Alt-Tab
    # 递归列出某个 Schema 的键值
    # gsettings list-recursively org.gnome.shell.extensions.coverflowalttab
    # gsettings set org.gnome.shell.extensions.coverflowalttab switcher-looping-method 'Flip Stack'
    gsettings set org.gnome.shell.extensions.coverflowalttab switcher-looping-method 'Carousel'
    gsettings set org.gnome.shell.extensions.coverflowalttab hide-panel false
    # 设置背景黯淡因素，越大越暗
    gsettings set org.gnome.shell.extensions.coverflowalttab dim-factor 0.0
    gsettings set org.gnome.shell.extensions.coverflowalttab animation-time 0.5
    # gsettings get org.gnome.shell.extensions.coverflowalttab easing-function
    # gsettings set org.gnome.shell.extensions.coverflowalttab easing-function 'ease-out-quad'
    # gsettings set org.gnome.shell.extensions.coverflowalttab easing-function 'ease-out-cubic'
    # gsettings set org.gnome.shell.extensions.coverflowalttab easing-function 'ease-out-quart'
    gsettings set org.gnome.shell.extensions.coverflowalttab easing-function 'ease-out-quint'
    # gsettings set org.gnome.shell.extensions.coverflowalttab easing-function 'ease-out-sine'
    # gsettings set org.gnome.shell.extensions.coverflowalttab preview-to-monitor-ratio 0.75
    # gsettings get org.gnome.shell.extensions.coverflowalttab preview-to-monitor-ratio
    # gsettings reset org.gnome.shell.extensions.coverflowalttab preview-to-monitor-ratio
    # 恢复默认设置
    # gsettings reset-recursively org.gnome.shell.extensions.coverflowalttab
    
    print_info "正在配置ddterm..."
    # ddterm，默认的切换快捷键 F12
    # gsettings list-recursively com.github.amezin.ddterm
    gsettings set com.github.amezin.ddterm background-opacity 1.0
    gsettings set com.github.amezin.ddterm hide-animation-duration 0.3
    gsettings set com.github.amezin.ddterm show-animation-duration 0.2
    # gsettings set com.github.amezin.ddterm window-size 0.6
    gsettings set com.github.amezin.ddterm hide-when-focus-lost true
    gsettings set com.github.amezin.ddterm hide-window-on-esc true
    # gsettings reset-recursively com.github.amezin.ddterm
    
    print_info "正在配置Gtk4 Desktop Icons NG..."
    # Gtk4 Desktop Icons NG
    # gsettings list-recursively org.gnome.shell.extensions.gtk4-ding
    gsettings set org.gnome.shell.extensions.gtk4-ding show-home false
    gsettings set org.gnome.shell.extensions.gtk4-ding show-trash false
    gsettings set org.gnome.shell.extensions.gtk4-ding show-volumes false
    # gsettings reset-recursively org.gnome.shell.extensions.gtk4-ding
    
    print_info "正在配置Hide Top Bar..."
    # 配置 Hide Top Bar
    # 递归列出某个 Schema 的键值
    # gsettings list-recursively org.gnome.shell.extensions.hidetopbar
    # 设置鼠标触发灵敏度（true/false）
    gsettings set org.gnome.shell.extensions.hidetopbar mouse-sensitive true
    gsettings set org.gnome.shell.extensions.hidetopbar animation-time-autohide 0.5
    gsettings set org.gnome.shell.extensions.hidetopbar animation-time-overview 0.5
    # 窗口被激活时不要总是显示 panel
    gsettings set org.gnome.shell.extensions.hidetopbar enable-active-window false
    # 恢复默认设置
    # gsettings reset-recursively org.gnome.shell.extensions.hidetopbar
    
    print_info "正在配置Ibus Tweaker..."
    # 配置 Ibus Tweaker
    # gsettings list-recursively org.gnome.shell.extensions.ibus-tweaker
    gsettings set org.gnome.shell.extensions.ibus-tweaker enable-custom-font true
    gsettings set org.gnome.shell.extensions.ibus-tweaker custom-font '思源黑体 CN Medium 12'
    gsettings set org.gnome.shell.extensions.ibus-tweaker enable-preset-theme true
    gsettings set org.gnome.shell.extensions.ibus-tweaker enable-clip-history true
    # 恢复默认设置
    # gsettings reset-recursively org.gnome.shell.extensions.ibus-tweaker
    
    # Logo Menu
    # gsettings list-recursively org.gnome.shell.extensions.logo-menu
    gsettings set org.gnome.shell.extensions.logo-menu menu-button-icon-image 1
    gsettings set org.gnome.shell.extensions.logo-menu menu-button-icon-size 20
    gsettings set org.gnome.shell.extensions.logo-menu show-activities-button false
    # 在 Just Profect 中也同时将 activities 隐藏
    gsettings set org.gnome.shell.extensions.just-perfection activities-button false
    # gsettings reset-recursively org.gnome.shell.extensions.logo-menu
    
    print_info "正在配置Night Theme Switcher..."
    # 递归列出某个 Schema 的键值
    # gsettings list-recursively org.gnome.shell.extensions.nightthemeswitcher.commands
    # gsettings get org.gnome.shell.extensions.nightthemeswitcher.commands sunrise
    # gsettings get org.gnome.shell.extensions.nightthemeswitcher.commands sunset
    gsettings set org.gnome.shell.extensions.nightthemeswitcher.commands enabled true
    # 使用 WhiteSur-*-solid 不透明 GTK 主题版本
    gsettings set org.gnome.shell.extensions.nightthemeswitcher.commands sunrise "gsettings set org.gnome.desktop.interface color-scheme 'default'\ngsettings set org.gnome.desktop.interface cursor-theme 'WhiteSur-cursors'\ngsettings set org.gnome.desktop.interface icon-theme 'WhiteSur-light'\ngsettings set org.gnome.shell.extensions.user-theme name 'WhiteSur-Light-solid'\ngsettings set org.gnome.desktop.interface gtk-theme 'WhiteSur-Light-solid'\ngsettings set org.gnome.desktop.wm.preferences theme 'WhiteSur-Light-solid'\ngsettings set org.gnome.shell.extensions.blur-my-shell.panel style-panel 1\ngsettings set org.gnome.shell.extensions.blur-my-shell.appfolder style-dialogs 2\ngsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(153,193,241)'\ngsettings set org.gnome.shell.extensions.blur-my-shell.dash-to-dock style-dash-to-dock 1"
    gsettings set org.gnome.shell.extensions.nightthemeswitcher.commands sunset "gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'\ngsettings set org.gnome.desktop.interface cursor-theme 'WhiteSur-cursors'\ngsettings set org.gnome.desktop.interface icon-theme 'WhiteSur-dark'\ngsettings set org.gnome.shell.extensions.user-theme name 'WhiteSur-Dark-solid'\ngsettings set org.gnome.desktop.interface gtk-theme 'WhiteSur-Dark-solid'\ngsettings set org.gnome.desktop.wm.preferences theme 'WhiteSur-Dark-solid'\ngsettings set org.gnome.shell.extensions.blur-my-shell.panel style-panel 2\ngsettings set org.gnome.shell.extensions.blur-my-shell.appfolder style-dialogs 3\ngsettings set org.gnome.shell.extensions.dash-to-dock background-color 'rgb(26,95,180)'\ngsettings set org.gnome.shell.extensions.blur-my-shell.dash-to-dock style-dash-to-dock 2"

    # Quick Settings Tweaks
    # 控制 GNOME 顶部面板快捷设置菜单（Quick Settings）的弹出样式和动画效果
    # gsettings list-recursively org.gnome.shell.extensions.quick-settings-tweaks
    # 启用或禁用 覆盖式菜单样式（即快捷设置面板以独立浮层形式弹出，而非传统的下拉样式）。
    gsettings set org.gnome.shell.extensions.quick-settings-tweaks overlay-menu-enabled true
    # gsettings reset-recursively org.gnome.shell.extensions.quick-settings-tweaks

    print_info "正在配置Rounded Window Corners Reborn..."
    # 配置 Rounded Window Corners Reborn
    # gsettings list-recursively org.gnome.shell.extensions.rounded-window-corners-reborn
    # 跳过Libadwaita/Libhandy应用（避免与GTK4应用冲突）
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn skip-libadwaita-app true
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn skip-libhandy-app true
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn tweak-kitty-terminal true
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn enable-preferences-entry true
    # 全局圆角设置（核心参数）
    # gsettings get org.gnome.shell.extensions.rounded-window-corners-reborn global-rounded-corner-settings
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn global-rounded-corner-settings "{'padding': <{'left': uint32 1, 'right': 1, 'top': 1, 'bottom': 1}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}"
    # 解决 jetbrains 软件的边框问题
    gsettings set org.gnome.shell.extensions.rounded-window-corners-reborn custom-rounded-corner-settings "{'jetbrains-idea': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-goland': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-webstorm': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-rustrover': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-datagrip': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-pycharm': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-studio': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>, 'jetbrains-clion': <{'padding': <{'left': uint32 2, 'right': 2, 'top': 2, 'bottom': 2}>, 'keepRoundedCorners': <{'maximized': true, 'fullscreen': true}>, 'borderRadius': <uint32 12>, 'smoothing': <0.2>, 'borderColor': <(1.0, 1.0, 1.0, 0.0)>, 'enabled': <true>}>}"
    # gsettings reset-recursively org.gnome.shell.extensions.rounded-window-corners-reborn

    print_info "正在配置Search Light..."
    # gsettings list-recursively org.gnome.shell.extensions.search-light
    gsettings set org.gnome.shell.extensions.search-light shortcut-search "['<Super>q']"
    # gsettings set org.gnome.shell.extensions.search-light show-panel-icon true
    # gsettings get org.gnome.shell.extensions.search-light border-radius
    gsettings set org.gnome.shell.extensions.search-light border-radius 6
    gsettings set org.gnome.shell.extensions.search-light animation-speed 200.0
    gsettings set org.gnome.shell.extensions.search-light background-color "(0.0, 0.0, 0.0, 0.9)"
    gsettings set org.gnome.shell.extensions.search-light blur-brightness 0.6
    gsettings set org.gnome.shell.extensions.search-light blur-sigma 50.0
    gsettings set org.gnome.shell.extensions.search-light blur-background true
    # gsettings set org.gnome.shell.extensions.search-light background-color (1.0, 1.0, 1.0, 0.25)
    # gsettings reset-recursively org.gnome.shell.extensions.search-light

    print_info "正在配置Show Desktop Button..."
    # gsettings list-recursively org.gnome.shell.extensions.show-desktop-button
    # 不隐藏当前激活的焦点窗口，他的全部隐藏
    gsettings set org.gnome.shell.extensions.show-desktop-button keep-focused true
    gsettings set org.gnome.shell.extensions.show-desktop-button shortcut "['<Super>h']"
    # gsettings reset-recursively org.gnome.shell.extensions.show-desktop-button

    print_info "正在配置Status Area Horizontal Spacing..."
    # Status Area Horizontal Spacing
    # gsettings list-recursively org.gnome.shell.extensions.status-area-horizontal-spacing
    gsettings set org.gnome.shell.extensions.status-area-horizontal-spacing hpadding 5
    # gsettings reset-recursively org.gnome.shell.extensions.status-area-horizontal-spacing
    
    print_info "正在配置Top Bar Organizer..."
    # Top Bar Organizer
    # gsettings list-recursively org.gnome.shell.extensions.top-bar-organizer
    gsettings set org.gnome.shell.extensions.top-bar-organizer left-box-order ['LogoMenu', 'appmenu-indicator']
    # gsettings set org.gnome.shell.extensions.top-bar-organizer center-box-order "['dateMenu']"
    gsettings set org.gnome.shell.extensions.top-bar-organizer right-box-order "['appindicator-kstatusnotifieritem-chrome_status_icon_1', 'vitalsMenu', 'workspace-indicator', 'FedoraUpdateIndicator', 'Show Desktop Button Indicator', 'ddterm', 'clipboardIndicator', 'drive-menu', 'screenRecording', 'screenSharing', 'dwellClick', 'a11y', 'keyboard', 'quickSettings']"
    # gsettings set org.gnome.shell.extensions.top-bar-organizer hide "[]"
    # gsettings set org.gnome.shell.extensions.top-bar-organizer show "[]"
    # gsettings reset-recursively org.gnome.shell.extensions.top-bar-organizer
    
    print_success "GNOME 扩展启用并配置完成！"
}    

# 安装字体、图标、主题
install_themes_and_icons() {
    print_info "正在安装并配置系统字体..."
    sudo dnf install -y \
    adobe-source-han-sans-cn-fonts \
    adobe-source-han-serif-cn-fonts \
    jetbrains-mono-fonts
    # 设置系统字体
    # 设置 GNOME 桌面的默认界面字体，影响范围：应用程序菜单、按钮、标签、对话框等 UI 元素的字体
    gsettings set org.gnome.desktop.interface font-name '思源黑体 CN Medium 12'
    # 设置文档类内容的默认字体，影响范围：文本编辑器、帮助文档、网页内容（某些应用中）等以“文档”形式展示的内容
    gsettings set org.gnome.desktop.interface document-font-name '思源宋体 CN Medium 12'
    # 设置等宽字体，影响范围：终端、代码编辑器
    gsettings set org.gnome.desktop.interface monospace-font-name 'JetBrains Mono Medium 12'
    # 设置窗口标题栏字体，影响范围：所有应用程序窗口顶部的标题文字
    gsettings set org.gnome.desktop.wm.preferences titlebar-font '思源黑体 CN Bold 12'
    # 字体渲染，调整字体轮廓以更好地对齐像素网格，从而提升小字号下的清晰度
    gsettings set org.gnome.desktop.interface font-hinting 'slight'
    # 启用字体抗锯齿（antialiasing），并指定子像素渲染方式
    gsettings set org.gnome.desktop.interface font-antialiasing 'rgba'


    print_info "正在安装并配置系统铃声..."
    # 安装 Ubuntu 的声音主题
    sudo dnf install -y yaru-sound-theme
    gsettings set org.gnome.desktop.sound theme-name 'Yaru'
    
    # 下载并安装 WhiteSur-cursors 光标主题
    if [ ! -d ~/.icons/WhiteSur-cursors ]; then
        print_info "正在下载 WhiteSur-cursors 光标主题..."
        cd ~/下载
        git clone https://gh-proxy.com/https://github.com/vinceliuice/WhiteSur-cursors.git --depth=1
        cd WhiteSur-cursors
        ./install.sh
        cd ~/下载
        rm -rf WhiteSur-cursors
    fi
    # 设置系统光标主题
    gsettings set org.gnome.desktop.interface cursor-theme 'WhiteSur-cursors'
    print_success "WhiteSur-cursors 光标启用并配置完成！"
    
    # 下载并安装 WhiteSur Icon 图标主题
    if [ ! -d ~/.icons/WhiteSur ]; then
        print_info "正在下载 WhiteSur Icon 图标主题..."
        cd ~/下载
        git clone https://gh-proxy.com/https://github.com/vinceliuice/WhiteSur-icon-theme.git --depth=1
        cd WhiteSur-icon-theme
        ./install.sh
        cd ~/下载
        rm -rf WhiteSur-icon-theme
    fi
    # 设置系统图标主题
    gsettings set org.gnome.desktop.interface icon-theme 'WhiteSur-dark'
    print_success "WhiteSur Icon 图标启用并配置完成！"
    
    # 下载并安装 WhiteSur GTK 主题
    if [ ! -d ~/.themes/WhiteSur-Light ]; then
        print_info "正在下载 WhiteSur GTK 主题..."
        cd ~/下载
        git clone https://gh-proxy.com/github.com/vinceliuice/WhiteSur-gtk-theme.git --depth=1
        # 修改 Nautilus 侧边栏不透明度，参考 https://github.com/vinceliuice/WhiteSur-gtk-theme/issues/1127
        sed -i 's/\$opacity: 0\.96/\$opacity: 1/g' ~/下载/WhiteSur-gtk-theme/src/sass/_colors.scss
        # grep '$opacity: ' ~/下载/WhiteSur-gtk-theme/src/sass/_colors.scss
        cd WhiteSur-gtk-theme
        # 安装 GTK 主题，设置主题不透明度变体。默认为所有变体
        ./install.sh -o solid -l --round
        # 设置 'WhiteSur' GDM/Flatpak 主题不透明度变体。默认值为 'normal'
        ./tweaks.sh -o solid
        # 在执行 ./tweaks.sh -f flat 安装 Firefox 主题时，Firefox 不能正在运行
        if pgrep firefox > /dev/null; then
            print_info "Firefox 正在运行，正在杀死进程..."
            pkill firefox
            sleep 2
        else
            print_info "Firefox 未在运行..."
            # 快速启动 Firefox 并在 3 秒后杀死它
            firefox & sleep 3 && pkill firefox
        fi
        # 安装 Firefox 主题
        ./tweaks.sh -f flat
        # 设置 GDM 要模糊自定义背景
        sudo ./tweaks.sh -g -b "$HOME/.local/share/backgrounds/wallpaper.jpg"
        # 将 WhiteSur 主题包连接到 Flatpak 仓库，可以解决部分应用无法使用 WhiteSur 主题问题，例如：Chrome、Edge
        sudo flatpak override --filesystem=xdg-config/gtk-3.0:ro
        sudo flatpak override --filesystem=xdg-config/gtk-4.0:ro
        # xdg-data/themes 是 ~/.local/share/themes 的标准化路径别名（Flatpak 优先识别）
	# :ro 表示只读权限，避免应用误修改主题文件。
	sudo flatpak override --filesystem=xdg-data/themes:ro
	sudo flatpak override --filesystem=xdg-data/icons:ro
	sudo flatpak override --filesystem=$HOME/.themes:ro
	sudo flatpak override --filesystem=$HOME/.icons:ro
        ./tweaks.sh -F -o solid
        cd ~/下载
        rm -rf WhiteSur-gtk-theme
    fi
    # 设置系统 GTK 主题
    gsettings set org.gnome.shell.extensions.user-theme name 'WhiteSur-Dark-solid'
    gsettings set org.gnome.desktop.interface gtk-theme 'WhiteSur-Dark-solid'
    gsettings set org.gnome.desktop.wm.preferences theme 'WhiteSur-Dark-solid'
    print_success "WhiteSur GTK 图标启用并配置完成！"
    
    print_success "主题和图标安装完成！"
}

# 清理系统
cleanup_system() {
    print_info "正在清理系统..."
    sudo dnf autoremove -y
    sudo dnf clean all
    flatpak uninstall --unused -y
    print_success "系统清理完成！"
}

# 主函数
main() {
    print_info "开始 Fedora Workstation 42 自动化配置..."
    
    # 检查权限
    check_root
    # 设置基础配置
    apply_default_settings
    
    # 执行配置步骤
    update_system
    configure_gnome_extensions
    install_themes_and_icons
    cleanup_system
    
    print_success "=========================================="
    print_success "Fedora 配置完成！"
    print_success "建议重启系统以应用所有更改。"
    print_success "=========================================="
    
    # 提示用户重启
    read -p "是否现在重启系统？(y/N): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        sudo reboot
    fi
}

# 执行主函数
main "$@"


# 将上述代码保存为 `fedora-setup.sh`
# 赋予执行权限 chmod +x fedora-setup.sh
# 运行脚本 ./fedora-setup.sh

# https://www.bilibili.com/video/BV1sC411b7J9?spm_id_from=333.788.recommend_more_video.2&trackid=web_related_0.router-related-2206419-k4qpm.1762664789143.659&vd_source=75333bb53891f589527eedfb7b2d5911
# https://github.com/brndnmtthws/conky
# 
sudo dnf -y install conky conky-manager/
# 全局菜单 https://github.com/Sominemo/Fildem-Gnome-45/wiki/Installation-of-the-updated-extension
# https://www.linuxuprising.com/2021/02/how-to-install-fildem-global-menu-and.html
Fildem

cd ~/下载
sudo dnf install bamf bamf-daemon keybinder3 unity-gtk2-module unity-gtk3-module appmenu-qt5 appmenu-qt5-profile.d python3-pip git
git clone https://gh-proxy.com/https://github.com/gonzaarcr/Fildem.git
cd ~/下载/Fildem-0.6.7
sudo python3 setup.py install --optimize=1
cp -r fildemGMenu@gonza.com ~/.local/share/gnome-shell/extensions/
